package com.maoshi.shop.platform.controller;


import cn.hutool.core.date.DateUtil;
import com.maoshi.shop.bean.param.OrderPayParam;
import com.maoshi.shop.bean.param.StatisticsRefundParam;
import com.maoshi.shop.service.OrderRefundService;
import com.maoshi.shop.service.OrderService;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author lhd on 2019/10/19.
 */
@RestController
@RequestMapping("/platform/statisticsOrder")
@AllArgsConstructor
public class StatisticsOrderController {

    private final OrderService orderService;
    private final OrderRefundService orderRefundService;


    @GetMapping("/orderPayByShopId")
    @ApiOperation(value = "通过时间获取支付信息")
    public ResponseEntity<OrderPayParam> orderPayByShopId() {
        OrderPayParam actualTotal = orderService.getPayUserCountByshopId(null,DateUtil.beginOfDay(DateUtil.date()), DateUtil.endOfDay(DateUtil.date()));
        return ResponseEntity.ok(actualTotal);
    }

    @GetMapping("/getActualTotalByHour")
    @ApiOperation(value = "通过24小时分段获取支付金额")
    public ResponseEntity<OrderPayParam> getActualTotalByHour() {
        OrderPayParam payList = orderService.getActualTotalByHour(
                null,DateUtil.beginOfDay(DateUtil.date()),DateUtil.endOfDay(DateUtil.date()));
        return ResponseEntity.ok(payList);
    }

    @GetMapping("/getActualTotalByDay")
    @ApiOperation(value = "通过天数分段获取支付金额")
    public ResponseEntity<List<OrderPayParam>> getActualTotalByDay() {
        List<OrderPayParam> payList = orderService.getActualTotalByDay(
                null,DateUtil.endOfDay(DateUtil.lastMonth()),DateUtil.endOfDay(DateUtil.date()));
        return ResponseEntity.ok(payList);
    }

    @GetMapping("/getOrderRefundByTime")
    @ApiOperation(value = "通过时间获取比率信息")
    public ResponseEntity<StatisticsRefundParam> getOrderRefundByTime() {
        StatisticsRefundParam refundParam = orderRefundService.getOrderRefundByShopId(
                null,DateUtil.beginOfDay(DateUtil.date()), DateUtil.endOfDay(DateUtil.date()));
        return ResponseEntity.ok(refundParam);
    }

    @GetMapping("/getOrderRefundDayByTime")
    @ApiOperation(value = "通过时间获取分段比率信息及退款金额信息")
    public ResponseEntity<List<StatisticsRefundParam>> getOrderRefundById() {
        List<StatisticsRefundParam> refundList = orderRefundService.getOrderRefundByShopIdAndDay(
                null,DateUtil.endOfDay(DateUtil.lastMonth()),DateUtil.endOfDay(DateUtil.date()));
        return ResponseEntity.ok(refundList);
    }

    @GetMapping("/getRefundRankingByProd")
    @ApiOperation(value = "根据商品名生成退款排行")
    public ResponseEntity<List<StatisticsRefundParam>> getRefundRankingByProd() {
        List<StatisticsRefundParam> refundList = orderRefundService.getRefundRankingByProd(
                null,DateUtil.endOfDay(DateUtil.lastMonth()),DateUtil.endOfDay(DateUtil.date()));
        return ResponseEntity.ok(refundList);
    }

  @GetMapping("/getRefundRankingByReason")
    @ApiOperation(value = "根据退款原因生成退款排行")
    public ResponseEntity<List<StatisticsRefundParam>> getRefundRankingByReason() {
        List<StatisticsRefundParam> refundList = orderRefundService.getRefundRankingByReason(
                null,DateUtil.endOfDay(DateUtil.lastMonth()),DateUtil.endOfDay(DateUtil.date()));
        return ResponseEntity.ok(refundList);
    }

}
